package outil;

public class TantQue implements Action {

    private final Predicat pPredicat;
    private final Action pAction;
    private final Action pActionBoucle;

    public final static Action instance(Predicat pPredicat, Action pActionBoucle, Action pAction) {
        return new TantQue(pPredicat, pActionBoucle, pAction);
    }

    public TantQue(Predicat pPredicat, Action pActionBoucle, Action pAction) {
        this.pPredicat = pPredicat;
        this.pActionBoucle = pActionBoucle;
        this.pAction = pAction;
    }

    @Override
    public void exec() {
        while (pPredicat.eval()) {
            pActionBoucle.exec();
            pAction.exec();
        }
    }
}
